﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Web.UI.WebControls;
using Meqs.Entity;
using Meqs.Entity.Parameters;
using Meqs.Logic;
using Meqs.Logic.Interface;
using Meqs.Utilities;

public partial class TeacherEval_School_ScoreInput_TeachTermInput : ScoreInputBasePage
{
    protected int historyId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string s = Request.Params["HistoryId"];
            if (!string.IsNullOrEmpty(s))
                int.TryParse(s, out historyId);


            BindHeadTable();
            BindBodyTable();
            //CreateTable();
            ClientScript.RegisterStartupScript(GetType(), "script", "setTableHeight();", true);

        }
    }

    protected string ReportTitle
    {
        get
        {
            string title = "{0}{1} {2}{3}学分报表";

            int schoolYear = SchoolYear;
            int term = Term;
            if (SchoolYear == -1 || Term == -1)
            {
                ISchoolInfoLogic schLogic = Container<ISchoolInfoLogic>.Instance;
                SchoolInfo sch = schLogic.FindBySchoolMark(SchoolMark);
                schoolYear = sch.SchoolYear;
                term = sch.SchoolTerm;
            }
            string termStr = term == 1 ? "上学期" : "下学期";
            return string.Format(title, Common.ConvertSchoolYear(schoolYear), termStr, Cause == null ? "" : Cause.CauseName, Common.ReportDateType(3));
        }
    }

    protected static string ExcelFileName
    {
        get
        {
            string title = "{0}{1} {2}{3}学分报表";

            int schoolYear = SchoolYear;
            int term = Term;
            if (SchoolYear == -1 || Term == -1)
            {
                ISchoolInfoLogic schLogic = Container<ISchoolInfoLogic>.Instance;
                SchoolInfo sch = schLogic.FindBySchoolMark(SchoolMark);
                schoolYear = sch.SchoolYear;
                term = sch.SchoolTerm;
            }
            string termStr = term == 1 ? "上学期" : "下学期";
            return string.Format(title, Common.ConvertSchoolYear(schoolYear), termStr, Cause == null ? "" : Cause.CauseName, Common.ReportDateType(3));
        }
    }

    protected string ReportSubTitle
    {
        get
        {
            string title = "学年：{1}";

            string strTerm = "";
            if (Term == 1)
                strTerm = "上学期";
            else
                strTerm = "下学期";

            //IClsInfoLogic clsLogic = Container<IClsInfoLogic>.Instance;

            //ClsInfo cls = clsLogic.FindById(ClsID);
            //if (cls == null)
            //    cls = new ClsInfo();
            return Year + "年" + strTerm;
        }
    }

    private int _tableWidth;

    protected void CreateTable()
    {
        int month = 0;
        if (Month == 0)
        {
            ITermInfoLogic termLogic = Container<ITermInfoLogic>.Instance;
            List<TermInfo> termInfo = (List<TermInfo>)termLogic.FindTermInfo(SchoolMark, SchoolYear, Term);
            month = termInfo[0].StartDate.Value.Month;
        }
        else
            month = Month;

        _tableWidth = 0;

        ITeacherEvalTypeLogic mtLogic = Container<ITeacherEvalTypeLogic>.Instance;
        ITeacherEvalItemLogic miLogic = Container<ITeacherEvalItemLogic>.Instance;
        ITeacherEvalDetailLogic mdLogic = Container<ITeacherEvalDetailLogic>.Instance;

        IList<TeacherEvalType> list;

        if (SchoolYear == -1 || Term == -1)
        {
            ISchoolInfoLogic schoolLogic = Container<ISchoolInfoLogic>.Instance;
            SchoolInfo schoolInfo = schoolLogic.FindBySchoolMark(SchoolMark);
            list = mtLogic.GetTeachHisType(SchoolMark, schoolInfo.SchoolYear, schoolInfo.SchoolTerm, HistoryId, "Teacher");
        }
        else
        {
            list = mtLogic.GetTeachHisType(SchoolMark, SchoolYear, Term, HistoryId, "Teacher");
        }
        int managerId = Common.GetUserInfo().UID;
        IList<TeacherInputEntity> sieList = mdLogic.GetTeacherInputEntityByTerm(HistoryId, EvalTeacherID, managerId, Year, month, SchoolYear, Term, SchoolMark);

        //    ListSort<ParamVal> sort = new ListSort<ParamVal>(pvList, "Index", true);
        //     pvList = sort.Sort();


        TableRow row = new TableRow();
        TableRow subRow = new TableRow();
        //row.Style["background-color"] = "#D4F1F9";
        //subRow.Style["background-color"] = "#D4F1F9";

        TableCell cell1 = new TableCell();
        cell1.Text = "姓名";
        //       cell1.CssClass = "FixedRowCol";

        row.Cells.Add(cell1);
        //  _tableWidth += 40;

        TableCell cell2 = new TableCell();
        cell2.Text = TeacherName;
        //    cell2.CssClass = "FixedRowCol";
        row.Cells.Add(cell2);
        //     _tableWidth += 100;

        TableCell cell3 = new TableCell();
        row.Cells.Add(cell3);

        tblHead.Rows.Add(row);
        foreach (TeacherEvalType mt in list)
        {
            int index = 0;
            IList<TeacherEvalItem> miList = miLogic.GetItemByType(SchoolMark, mt.RID);

            TableCell tempCell = new TableCell();
            foreach (TeacherEvalItem item in miList)
            {
                row = new TableRow();

                TableCell cell = new TableCell();
                cell.Text = mt.Caption;
                //    cell.CssClass = "FixedRow";
                cell.Style["width"] = (60 * miList.Count) + "px";
                _tableWidth += 60 * miList.Count;


                TableCell subCell = new TableCell();
                subCell.Text = item.Caption + (item.Type == 1 ? String.Format("({0}分)", item.Param * item.Operator) : "(次)");
                //     subCell.CssClass = "FixedRow";
                //     subCell.Style["width"] = "60px";
                subRow.Cells.Add(subCell);
                ParamVal pv2 = new ParamVal();
                pv2.Index = index;
                pv2.ItemID = item.RID;
                _paramVals.Clear();
                _paramVals.Add(pv2);

                row.Cells.Add(subCell);

                IList<ParamVal> pvList = new List<ParamVal>();
                foreach (TeacherInputEntity item2 in sieList)
                {
                    ParamVal pv = new ParamVal();
                    pv.ItemID = item2.ItemID;
                    if (!_paramVals.Contains(pv)) continue;
                    ParamVal p = _paramVals[_paramVals.IndexOf(pv)];
                    p.Type = item2.Type;
                    p.Param = item2.Param;
                    p.Score = item2.Score;
                    p.Operator = (int)item.Operator;

                    pvList.Add(p);
                }

                //开始穿件加分 加次的输入单元格
                subCell = new TableCell();

                foreach (ParamVal pv in pvList)
                {
                    if (pv.ItemID != item.RID)
                        continue;
                    subCell = new TableCell();
                    //        subCell.Style["border-top"] = "0px";

                    //        subCell.Style["width"] = "60px";
                    // 计次
                    if (pv.Type == 2)
                    {
                        // 可编辑状态
                        if (IsModify)
                        {
                            string html = string.Format(ScoreInputNumericHtmlStr, "txt_" + pv.ItemID + "_" + EvalTeacherID + "_2", pv.Param == 0 ? "" : pv.Param.ToString(), pv.Score, pv.Operator);
                            subCell.Text = html;
                            subCell.Attributes.Add("onmouseover", "mover(this);");
                            subCell.Attributes.Add("onmouseout", "mout(this);");
                        }
                        else
                        {
                            subCell.Text = pv.Param == 0 ? "" : pv.Param.ToString();
                            subCell.Style["text-align"] = "right";
                        }
                    }
                    // 计分
                    if (pv.Type == 1)
                    {
                        // 可编辑状态 
                        if (IsModify)
                        {
                            string html = string.Format(ScoreInputScoreHtmlStr, "txt_" + pv.ItemID + "_" + EvalTeacherID + "_1", pv.Param == 0 ? "" : pv.Param.ToString(), pv.Score);
                            subCell.Text = html;
                        }
                        else
                        {
                            subCell.Text = pv.Param == 0 ? "" : pv.Param.ToString();
                            subCell.Style["text-align"] = "right";
                        }
                    }
                }


                if (index == 0)
                {
                    tempCell = cell;
                    row.Cells.Add(cell);
                }
                row.Cells.Add(subCell);
                tblHead.Rows.Add(row);

                index++;
            }
            tempCell.RowSpan = index;

        }
    }

    #region 绑定表格

    protected void BindHeadTable()
    {
        int month = 0;
        if (Month == 0)
        {
            ITermInfoLogic termLogic = Container<ITermInfoLogic>.Instance;
            List<TermInfo> termInfo = (List<TermInfo>)termLogic.FindTermInfo(SchoolMark, SchoolYear, Term);
            month = termInfo[0].StartDate.Value.Month;
        }
        else
            month = Month;
        _tableWidth = 0;
        TableRow row = new TableRow();
        row.Style["background-color"] = "#D4F1F9";
        TableCell cell1 = new TableCell();
        cell1.Text = "类别";
        cell1.Style["text-align"] = "left";
        cell1.Style["padding-left"] = "5px";
        cell1.CssClass = "FixedRow";
        cell1.Style["width"] = "120px";
        row.Cells.Add(cell1);
        _tableWidth += 120;

        TableCell cell11 = new TableCell();
        cell11.Text = "类别";
        cell11.Style["text-align"] = "left";
        cell11.Style["padding-left"] = "5px";
        cell11.CssClass = "FixedRow";
        cell11.Style["width"] = "260px";
        row.Cells.Add(cell11);
        _tableWidth += 260;

        TableCell cell12 = new TableCell();
        cell12.Text = "数据录入";
        cell12.CssClass = "FixedRow";
        cell12.Style["width"] = "60px";
        row.Cells.Add(cell12);
        _tableWidth += 60;
        tblHead.Rows.Add(row);
        tblHead.Style["width"] = _tableWidth + "px";
        //_tableWidth = 0;

        //ITeacherEvalTypeLogic mtLogic = Container<ITeacherEvalTypeLogic>.Instance;
        //ITeacherEvalItemLogic miLogic = Container<ITeacherEvalItemLogic>.Instance;
        //IList<TeacherEvalType> list;

        //if (SchoolYear == -1 || Term == -1)
        //{
        //    ISchoolInfoLogic schoolLogic = Container<ISchoolInfoLogic>.Instance;
        //    SchoolInfo schoolInfo = schoolLogic.FindBySchoolMark(SchoolMark);
        //    list = mtLogic.GetTeachHisType(SchoolMark, schoolInfo.SchoolYear, schoolInfo.SchoolTerm, HistoryId, "Teacher");
        //}
        //else
        //{
        //    list = mtLogic.GetTeachHisType(SchoolMark, SchoolYear, Term, HistoryId, "Teacher");
        //}

        //TableRow row = new TableRow();
        //TableRow subRow = new TableRow();
        //row.Style["background-color"] = "#D4F1F9";
        //subRow.Style["background-color"] = "#D4F1F9";

        //TableCell cell1 = new TableCell();
        //cell1.Text = "序号";
        //cell1.RowSpan = 2;
        //cell1.CssClass = "FixedRowCol";
        //cell1.Style["width"] = "40px";
        //row.Cells.Add(cell1);
        //_tableWidth += 40;

        //TableCell cell2 = new TableCell();
        //cell2.Text = "姓名";
        //cell2.RowSpan = 2;
        //cell2.CssClass = "FixedRowCol";
        //cell2.Style["width"] = "100px";
        //row.Cells.Add(cell2);
        //_tableWidth += 100;

        //int index = 0;
        //foreach (TeacherEvalType mt in list)
        //{
        //    TableCell cell = new TableCell();
        //    cell.Text = mt.Caption;
        //    IList<TeacherEvalItem> miList = miLogic.GetItemByType(SchoolMark, mt.RID);
        //    cell.ColumnSpan = miList.Count;
        //    cell.CssClass = "FixedRow";
        //    cell.Style["width"] = (60 * miList.Count) + "px";
        //    _tableWidth += 60 * miList.Count;
        //    foreach (TeacherEvalItem item in miList)
        //    {
        //        TableCell subCell = new TableCell();
        //        subCell.Text = item.Caption + (item.Type == 1 ? "(分)" : "(次)");
        //        subCell.CssClass = "FixedRow";
        //        subCell.Style["width"] = "60px";
        //        subRow.Cells.Add(subCell);
        //        ParamVal pv = new ParamVal();
        //        pv.Index = index;
        //        pv.ItemID = item.RID;
        //        _paramVals.Add(pv);
        //        index++;
        //    }
        //    row.Cells.Add(cell);
        //}
        //TableCell cell3 = new TableCell();
        //cell3.Text = "备注";
        //cell3.RowSpan = 2;
        //cell3.CssClass = "FixedRow";
        //cell3.Style["width"] = "200px";
        //row.Cells.Add(cell3);
        //_tableWidth += 200;
        //tblHead.Rows.Add(row);
        //tblHead.Rows.Add(subRow);
        //tblHead.Style["width"] = _tableWidth + "px";
    }

    protected void BindBodyTable()
    {
        int month = 0;
        if (Month <= 0)
        {
            ITermInfoLogic termLogic = Container<ITermInfoLogic>.Instance;
            List<TermInfo> termInfo = (List<TermInfo>)termLogic.FindTermInfo(SchoolMark, SchoolYear, Term);
            month = termInfo[0].StartDate.Value.Month;
        }
        else
            month = Month;

        ITeacherEvalTypeLogic mtLogic = Container<ITeacherEvalTypeLogic>.Instance;
        ITeacherEvalItemLogic miLogic = Container<ITeacherEvalItemLogic>.Instance;

        ITeacherInfoLogic sLogic = Container<ITeacherInfoLogic>.Instance;
        ITeacherEvalDetailLogic mdLogic = Container<ITeacherEvalDetailLogic>.Instance;
        ITeacherEvalRemarkLogic mrLogic = Container<ITeacherEvalRemarkLogic>.Instance;


        IList<TeacherEvalType> list;

        if (SchoolYear == -1 || Term == -1)
        {
            ISchoolInfoLogic schoolLogic = Container<ISchoolInfoLogic>.Instance;
            SchoolInfo schoolInfo = schoolLogic.FindBySchoolMark(SchoolMark);
            list = mtLogic.GetTeachHisType(SchoolMark, schoolInfo.SchoolYear, schoolInfo.SchoolTerm, HistoryId, "Teacher");
        }
        else
        {
            list = mtLogic.GetTeachHisType(SchoolMark, SchoolYear, Term, HistoryId, "Teacher");
        }

        List<int> itemIdList = new List<int>();
        foreach (TeacherEvalType mt in list)
        {
            IList<TeacherEvalItem> miList = miLogic.GetItemByType(SchoolMark, mt.RID);
            if (miList.Count > 0)
            {
                int index = 0;
                TableRow row = new TableRow();

                TableCell cell = new TableCell();
                cell.Text = mt.Caption;
                cell.RowSpan = miList.Count;
                cell.Style["text-align"] = "left";
                cell.Style["padding-left"] = "5px";

                row.Cells.Add(cell);
                tblHead.Rows.Add(row);
                foreach (TeacherEvalItem item in miList)
                {
                    if (index != 0)
                    {
                        row = new TableRow();
                        tblHead.Rows.Add(row);
                    }
                    TableCell subCell = new TableCell();
                    subCell.Style["text-align"] = "left";
                    subCell.Style["padding-left"] = "5px";
                    subCell.Text = item.Caption + (item.Type == 1 ? String.Format("({0}分)", item.Param * item.Operator) : "(次)");
                    subCell.Style["width"] = "260px";
                    row.Cells.Add(subCell);


                    ParamVal pv = new ParamVal();
                    pv.Index = index;
                    pv.ItemID = item.RID;
                    _paramVals.Add(pv);
                    index++;

                    itemIdList.Add(item.RID);
                }
            }
        }
        TableRow row1 = new TableRow();
        TableCell cell3 = new TableCell();
        cell3.Style["text-align"] = "left";
        cell3.Style["padding-left"] = "5px";
        cell3.Text = "备注";
        cell3.Style["display"] = "none";
        row1.Cells.Add(cell3);

        tblHead.Rows.Add(row1);

        int managerId = Common.GetUserInfo().UID;
        IList<TeacherInputEntity> sieList = mdLogic.GetTeacherInputEntityByTerm(HistoryId, EvalTeacherID, managerId, Year, month, SchoolYear, Term, SchoolMark);
        IList<ParamVal> pvList = new List<ParamVal>();
        foreach (TeacherInputEntity item in sieList)
        {
            ParamVal pv = new ParamVal();
            pv.ItemID = item.ItemID;
            if (!_paramVals.Contains(pv)) continue;
            ParamVal p = _paramVals[_paramVals.IndexOf(pv)];
            p.Type = item.Type;
            p.Param = item.Param;
            p.Score = item.Score;
            p.Operator = item.Operator;
            pvList.Add(p);
        }
        ListSort<ParamVal> sort = new ListSort<ParamVal>(pvList, "Index", true);
        pvList = sort.Sort();
        int inputindex = 1;
        foreach(int itemId in itemIdList)
        {
            foreach (ParamVal pv in pvList)
            {
                if (pv.ItemID != itemId)
                    continue;
                TableCell subCell = new TableCell();
                subCell.Style["border-top"] = "0px";

                subCell.Style["width"] = "60px";
                // 计次
                if (pv.Type == 2)
                {
                    // 可编辑状态
                    if (IsModify)
                    {
                        string html = string.Format(ScoreInputNumericHtmlStr, "txt_" + pv.ItemID + "_" + EvalTeacherID + "_2", pv.Param == 0 ? "" : pv.Param.ToString(), pv.Score, pv.Operator);
                        subCell.Text = html;
                        subCell.Attributes.Add("onmouseover", "mover(this);");
                        subCell.Attributes.Add("onmouseout", "mout(this);");
                    }
                    else
                    {
                        subCell.Text = pv.Param == 0 ? "" : pv.Param.ToString();
                        subCell.Style["text-align"] = "right";
                    }
                }
                // 计分
                if (pv.Type == 1)
                {
                    // 可编辑状态 
                    if (IsModify)
                    {
                        string html = string.Format(ScoreInputScoreHtmlStr, "txt_" + pv.ItemID + "_" + EvalTeacherID + "_1", pv.Param == 0 ? "" : pv.Param.ToString(), pv.Score);
                        subCell.Text = html;
                    }
                    else
                    {
                        subCell.Text = pv.Param == 0 ? "" : pv.Param.ToString();
                        subCell.Style["text-align"] = "right";
                    }
                }
                tblHead.Rows[inputindex].Cells.Add(subCell);
                inputindex++;
            } 
        }


        TeacherEvalRemark mr = mrLogic.GetRemarkByTeacher(HistoryId, EvalTeacherID, managerId, 4, Year, month, SchoolYear, Term, SchoolMark);


        TableCell cellRemark = new TableCell();

        cellRemark.Style["border-top"] = "0px";
        string span = "&nbsp;<span id=\"span_{0}\" title=\"{1}\">{2}</span>";
        span = string.Format(span, EvalTeacherID, mr == null ? "" : mr.Data, mr == null ? "" : mr.Data.Length > 20 ? mr.Data.Substring(0, 20) + "..." : mr.Data);
        cellRemark.Text = span;
        cellRemark.Attributes.Add("TeacherID", EvalTeacherID.ToString());
        cellRemark.Attributes.Add("TeacherName", TeacherName);
        if (IsModify) cellRemark.Attributes.Add("onclick", "displayRemark(this)");
        cellRemark.ColumnSpan = 2;
        cellRemark.Style["display"] = "none";
        cellRemark.Style["width"] = "320px";
        cellRemark.Style["text-align"] = "left";
        tblHead.Rows[inputindex].Cells.Add(cellRemark);


        //ITeacherInfoLogic sLogic = Container<ITeacherInfoLogic>.Instance;
        //ITeacherEvalDetailLogic mdLogic = Container<ITeacherEvalDetailLogic>.Instance;
        //ITeacherEvalRemarkLogic mrLogic = Container<ITeacherEvalRemarkLogic>.Instance;

        //TableRow row = new TableRow();
        //TableCell cellSNo = new TableCell();
        //cellSNo.Style["border-top"] = "0px";
        //cellSNo.Text = 1 + "&nbsp;";
        //cellSNo.CssClass = "FixedCol";
        //cellSNo.Style["width"] = "40px";
        //cellSNo.Style["text-align"] = "right";
        //row.Cells.Add(cellSNo);

        //TableCell cellSName = new TableCell();
        //cellSName.Style["border-top"] = "0px";
        //cellSName.CssClass = "FixedCol";
        //cellSName.Text = "&nbsp;" + TeacherName;
        //cellSName.Style["width"] = "100px";
        //cellSName.Style["text-align"] = "left";
        //row.Cells.Add(cellSName);


        //int managerId = Common.GetUserInfo().UID;
        //IList<TeacherInputEntity> sieList = mdLogic.GetTeacherInputEntityByTerm(HistoryId, EvalTeacherID,managerId, Year, month, SchoolYear, Term, SchoolMark);
        //IList<ParamVal> pvList = new List<ParamVal>();
        //foreach (TeacherInputEntity item in sieList)
        //{
        //    ParamVal pv = new ParamVal();
        //    pv.ItemID = item.ItemID;
        //    if (!_paramVals.Contains(pv)) continue;
        //    ParamVal p = _paramVals[_paramVals.IndexOf(pv)];
        //    p.Type = item.Type;
        //    p.Param = item.Param;
        //    p.Score = item.Score;
        //    p.Operator = item.Operator;
        //    pvList.Add(p);
        //}
        //ListSort<ParamVal> sort = new ListSort<ParamVal>(pvList, "Index", true);
        //pvList = sort.Sort();
        //foreach (ParamVal pv in pvList)
        //{
        //    TableCell subCell = new TableCell();
        //    subCell.Style["border-top"] = "0px";

        //    subCell.Style["width"] = "60px";
        //    // 计次
        //    if (pv.Type == 2)
        //    {
        //        // 可编辑状态
        //        if (IsModify)
        //        {
        //            string html = string.Format(ScoreInputNumericHtmlStr, "txt_" + pv.ItemID + "_" + EvalTeacherID + "_2", pv.Param == 0 ? "" : pv.Param.ToString(), pv.Score, pv.Operator);
        //            subCell.Text = html;
        //            subCell.Attributes.Add("onmouseover", "mover(this);");
        //            subCell.Attributes.Add("onmouseout", "mout(this);");
        //        }
        //        else
        //        {
        //            subCell.Text = pv.Param == 0 ? "" : pv.Param.ToString();
        //            subCell.Style["text-align"] = "right";
        //        }
        //    }
        //    // 计分
        //    if (pv.Type == 1)
        //    {
        //        // 可编辑状态 
        //        if (IsModify)
        //        {
        //            string html = string.Format(ScoreInputScoreHtmlStr, "txt_" + pv.ItemID + "_" + EvalTeacherID + "_1", pv.Param == 0 ? "" : pv.Param.ToString());
        //            subCell.Text = html;
        //        }
        //        else
        //        {
        //            subCell.Text = pv.Param == 0 ? "" : pv.Param.ToString();
        //            subCell.Style["text-align"] = "right";
        //        }
        //    }

        //    row.Cells.Add(subCell);
        //}
        //tblHead.Rows.Add(row);
        //tblHead.Style["width"] = _tableWidth + "px";

        //// 备注

        //TeacherEvalRemark mr = mrLogic.GetRemarkByTeacher(HistoryId, EvalTeacherID,managerId, 4, Year, month, SchoolYear, Term, SchoolMark);

        ////     StuCauseEvalRemark mr = mrLogic.GetRemarkByStudent(info.RID, CauseID, 3, Year, Month, SchoolYear, Term, SchoolMark);
        //TableCell cellRemark = new TableCell();
        ////if (j == 0) 
        //cellRemark.Style["border-top"] = "0px";
        //string span = "&nbsp;<span id=\"span_{0}\" title=\"{1}\">{2}</span>";
        //span = string.Format(span, EvalTeacherID, mr == null ? "" : mr.Data, mr == null ? "" : mr.Data.Length > 20 ? mr.Data.Substring(0, 20) + "..." : mr.Data);
        //cellRemark.Text = span;
        //cellRemark.Attributes.Add("TeacherID", EvalTeacherID.ToString());
        //cellRemark.Attributes.Add("TeacherName", TeacherName);
        //if (IsModify) cellRemark.Attributes.Add("onclick", "displayRemark(this)");
        //cellRemark.Style["width"] = "200px";
        //cellRemark.Style["text-align"] = "left";
        //row.Cells.Add(cellRemark);
        //tblHead.Rows.Add(row);
        //tblHead.Style["width"] = _tableWidth + "px";

    }


    #endregion


    /// <summary>
    /// 保存单据
    /// </summary>
    /// <param name="jsonStr"></param>
    /// <param name="causeID"></param>
    /// <param name="clsID"></param>
    /// <param name="schoolYear"></param>
    /// <param name="term"></param>
    /// <param name="year"></param>
    /// <param name="month"></param>
    /// <returns></returns>
    [WebMethod]
    public static bool SaveScoreInput(int historyId, string jsonStr, int schoolYear, int term, int year, int month)
    {
        try
        {
            IList<VItems> list = ConvertJson(jsonStr);

            int? syear = schoolYear == -1 ? (int?)null : schoolYear;
            int? sterm = term == -1 ? (int?)null : term;

            ITeacherEvalSubmitRecordLogic scesrLogic = Container<ITeacherEvalSubmitRecordLogic>.Instance;
            return scesrLogic.SaveOrUpdateRecord(list, historyId, 4, year, month, syear, sterm, Common.GetUserInfo().UID, SchoolMark);
        }
        catch (Exception e)
        {

            throw;
        }
    }

    private static IList<VItems> ConvertJson(string jsonStr)
    {
        JavaScriptSerializer jss = new JavaScriptSerializer();
        return jss.Deserialize<IList<VItems>>(jsonStr);
    }
    protected void btnReflesh_Click(object sender, EventArgs e)
    {
        tblHead.Rows.Clear();
        tblHead.Rows.Clear();
        BindHeadTable();
        BindBodyTable();
    }

    [WebMethod]
    public static string GetExcel(ExcelTableCell[][] cells, int causeID)
    {
        string temp_path = HttpContext.Current.Server.MapPath("../../../");
        string save_path = temp_path + "\\download\\" + ExcelFileName + ".xls";
        HttpContext.Current.Session["filepath"] = save_path;
        ExcelUtil.ExcelExport(save_path, ConvertToCause(causeID) + "学分报表", 2, 0, cells);
        return "";
    }

    private static string ConvertToCause(int causeID)
    {
        return Container<IGlobalCauseInfoLogic>.Instance.FindById(causeID).CauseName;
    }
}
